package com.dmpp.mes.service.impl;


import com.dmpp.mes.bean.RespEnum;
import com.dmpp.mes.bean.ResponseData;
import com.dmpp.mes.dao.AromaMapper;
import com.dmpp.mes.dao.BomMapper;
import com.dmpp.mes.parameterInfo.Aroma;
import com.dmpp.mes.parameterInfo.Bom;
import com.dmpp.mes.service.AromaService;
import com.dmpp.mes.service.BomService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service(value = "BomService")

public class BomServiceImpl implements BomService {

    @Autowired
    private BomMapper mapper;

    @Override
    public ResponseData findAll(Bom bom) {
        ResponseData responseData = new ResponseData();
        PageInfo pageInfo = new PageInfo<>(mapper.findAll(bom));
        responseData.setData(pageInfo);
        return responseData;
    }

    @Override
    public ResponseData findByMaterielNo(Bom bom) {
        ResponseData responseData = new ResponseData();
        responseData.setData(mapper.findByMaterielNo(bom));
        return responseData;
    }

    @Override
    public ResponseData insert(Bom bom) {
        ResponseData responseData = new ResponseData();
       Bom bom1= mapper.findByMaterielNo(bom);

       if (bom1==null){
            mapper.insert(bom);
       }else {
            responseData.setCodeEnum(RespEnum.ERROR2001);
        }
        return responseData;
    }

    @Override
    public ResponseData updateByCode(Bom bom) {
        return null;
    }


    @Override
    public ResponseData delete(Bom bom) {
        ResponseData responseData = new ResponseData();
        mapper.delete(bom);
        return responseData;
    }
}
